﻿using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Shared.Service.DataScopes.UserPolicyScopes
{
    /// <summary>
    /// 用户政策（权限） 的数据范围 作用在用户政策维度上
    /// </summary>
    public class UserPolicyScopeProvider : DataScopeProvider, IUserPolicyScopeProvider
    {
        public const string ProviderName = "UP";

        public override string Name => ProviderName;
      
        public UserPolicyScopeProvider(IDataScopeStore policyScopeStore) : base(policyScopeStore)
        {

        }

        public async Task<List<UserPolicyDataScope>> GetScopesAsync(string userId, string policyName)
        {
            var scopes = await this.DataScopeStore.GetDataScopesAsync(policyName, ProviderName, userId);
            return scopes.Select(s => new UserPolicyDataScope(s)).ToList();
        }
    }
}
